<%@page import="com.legendshop.oa.util.PropertiesUtil"%>
<%@page import="com.legendshop.oa.constants.SysParameterEnum"%>
<%@ page language="java" pageEncoding="UTF-8"%>
<%@ include file="/WEB-INF/pages/common/taglib.jsp"%>
<%@ include file="/WEB-INF/pages/common/back-common.jsp"%>
<%@ include file="/WEB-INF/pages/common/jquery2.1.4.jsp"%>
<%@ include file="/WEB-INF/pages/common/back-dialog.jsp"%>
<html>
<head>
<title>创建</title>
<script src="<ls:templateResource item='/resources/plugins/My97DatePicker/WdatePicker.js'/>" type="text/javascript"></script>
<script type='text/javascript' src="<ls:templateResource item='/resources/common/js/jquery.validate.js'/>" /></script>
<link rel="stylesheet" type="text/css" media="screen" href="${contextPath}/resources/common/css/errorform.css" />
<link href="<ls:templateResource item='/resources/plugins/select2-4.0/select2.css'/>" rel="stylesheet" />
<script src="<ls:templateResource item='/resources/plugins/select2-4.0/select2.full.min.js'/>" type="text/javascript"></script>
<script src="<ls:templateResource item='/resources/plugins/select2-4.0/i18n/zh-CN.js'/>" type="text/javascript"></script>
<script src="<ls:templateResource item='/resources/plugins/select2-4.0/makeSelect2.js'/>" type="text/javascript"></script>
<link rel="stylesheet" href="<ls:templateResource item='/resources/plugins/kindeditor/themes/default/default.css'/>" />
<link rel="stylesheet" href="<ls:templateResource item='/resources/plugins/kindeditor/plugins/code/prettify.css'/>" />
<script charset="utf-8" src="<ls:templateResource item='/resources/plugins/kindeditor/kindeditor-min.js'/>"></script>
<script charset="utf-8" src="<ls:templateResource item='/resources/plugins/kindeditor/lang/zh_CN.js'/>"></script>

  <%
  request.setAttribute("workingHoursPerWeek",  PropertiesUtil.getObject(SysParameterEnum.WORKING_HOURS_PER_WEEK, Long.class));
  %>

</head>
<body>
	<form method="post" id="form1">
		<input id="id" name="id" value="${weekLog.id}" type="hidden"> 
		<input id="year" name="year" value="${weekLog.year}" type="hidden">
		<input id="weekNo" name="weekNo" value="${weekLog.weekNo}" type="hidden">
		<input id="workTime" name="workTime" value="${weekLog.workTime}" type="hidden" >
		<input id="userName" name="userName" value="${userName}" type="hidden" >
		<input id="reviewed" name="reviewed" value="0" type="hidden" >
		<div align="center">
			<table border="0" align="center" class="${tableclass}" id="col1" style="width: 100%">
				<thead>
					<tr class="sortable">
						<th colspan="2" style="height: 30px; text-align: center; vertical-align: middle;">${adminUser.realName}  创建第${weekLog.weekNo}周周报 
						  <a href="${contextPath}/admin/dailylog/query" target="_blank">(${weekLog.startDate} - ${weekLog.endDate})</a> 
						  <c:choose>
								<c:when test="${weekLog.workTime < workingHoursPerWeek}">
                            			    -<a href="${contextPath}/admin/dailylog/query" target="_blank"><font color="red">总工时：${weekLog.workTime}小时, 请先录入工时. 最少${workingHoursPerWeek}工时</font></a>
								</c:when>
								<c:otherwise>
									<font color="green">工时：${weekLog.workTime}小时</font>
								</c:otherwise>
							</c:choose>
						</th>
					</tr>
				</thead>
				<tr>
					<td>我的里程碑与目标(Objective) :
					</td>
					<td>
						<c:forEach items="${myTask}" var="task" varStatus="status">
						 ${status.count}. ${task.text}//${task.customText1} <br/>
						</c:forEach>
					</td>
				</tr>
				<tr>
					<td>本周完成工作<br/>
						(Key Result) : <font color="ff0000">*</font>
					</td>
					<td><textarea style="height: 100px; width: 600px;" id="thisWeekLog" name="thisWeekLog">${weekLog.thisWeekLog}</textarea></td>
				</tr>
				<tr>
					<td>下周工作计划:</td>
					<td><textarea style="height: 100px; width: 600px;" id="nextWeekPlan" name="nextWeekPlan">${weekLog.nextWeekPlan}</textarea></td>
				</tr>
				<tr>
					<td>项目经理备注(Feedback 需协调帮助、建议/反映)</td>
					<td><textarea style="height: 100px; width: 600px;"  name="feedback" id="feedback" style="width: 700px; height: 200px; visibility: hidden;">${weekLog.feedback}</textarea></td>
				</tr>
				<c:if test="${not empty weekLogReportList }">
				<tr style="border: 0px;margin: 0px;padding: 0px;">
					<td>项目耗时统计<br/>
						(Actual Result)</td>
					<td>
							<c:forEach items="${weekLogReportList}" var="log">
							<div class="div1">
								<div class="div2">${log.projectName}</div>
								<div class="div3">${log.consumed}小时</div>
							</div>
							</c:forEach>

					</td>
				</tr>
				</c:if>
				<tr>
					<td colspan="2">
						<div align="center">
						    <c:if test="${weekLog.reviewed ne 1}">
						        <c:choose>
						        	<c:when test="${isMycolleague}">
						        	    <input type="button" name="Audit" id="Audit" value="审核通过" />
										<input type="button" name="Submit" id="Submit" value="提交" />
						        	</c:when>
						        	<c:otherwise>
						        	  <input type="button" name="Submit" id="Submit" value="提交" />
						        	</c:otherwise>
						        </c:choose>
						    
							    
							</c:if>
							 <input type="button" value="关闭" onclick="javascript:cancelDialog()" />
						</div>
					</td>
				</tr>
			</table>
		</div>
	</form>
	<style>
		.div1 {width:400px;border:1px}
		.div2 {min-width:300px;height:20px;float:left;border:0px solid}
		.div3 {min-width:100px;height:20px;float:left;border:0px solid}
	</style>
	<script charset="utf-8" src="<ls:templateResource item='/resources/plugins/kindeditor/plugins/code/prettify.js'/>"></script>
	<script language="javascript">
		$.validator.setDefaults({});
		var contextPath = '${contextPath}';
		$(document)
				.ready(
						function() {
							// parent.closeDropdown(); //再执行关闭   	
							jQuery("#form1").validate({
								rules : {
									thisWeekLog : {
										required : true
									},
									workTime : {
										min :  ${workingHoursPerWeek}
									}
								},
								messages : {
									thisWeekLog : {
										required : "请录入本周完成工作"
									},
									workTime : {
										range : "本周工作量不能少于" + ${workingHoursPerWeek} + "小时"
									}
								}
							});

							//binding Submit
							$("#Submit").click(function() {
												//关键所在，同步输入的值到textarea中
												//newsKindEditor.sync();
												if ($("#form1").valid()) {
													var formData = $("#form1").serialize();
													$.ajax({
																type : 'post', // 提交方式 get/post
																url : "${contextPath}/admin/weekLog/save", // 需要提交的 url
																data : formData,
																dataType : 'json',
																error : function(jqXHR,textStatus,errorThrown) {
																	layer.alert("保存失败"+ textStatus);
																},
																success : function(data) { // data 保存提交后返回的数据，一般为 json 数据
																	// 此处可对 data 作相关处理
																	if ("success" == data) {
																		layer.msg("保存周报成功");
																		closeDialog();
																	}else if("TimenotEnough" == data)
																		layer.msg("工时不足" + ${workingHoursPerWeek} + "小时,请先填写完毕日报",{icon: 3});
																	else {
																		layer.msg("保存周报失败: " + data,{icon: 3});
																		//closeDialog();
																	}

																}
															});
													return false; // 阻止表单自动提交事件
												};
											});
							
							//审核
							$("#Audit").click(function() {
												$("#reviewed").val(1);
												if ($("#form1").valid()) {
													var formData = $("#form1").serialize();
													$.ajax({
																type : 'post', // 提交方式 get/post
																url : "${contextPath}/admin/weekLog/save", // 需要提交的 url
																data : formData,
																dataType : 'json',
																error : function(jqXHR,textStatus,errorThrown) {
																	layer.alert("保存失败"+ textStatus);
																},
																success : function(data) { // data 保存提交后返回的数据，一般为 json 数据
																	// 此处可对 data 作相关处理
																	if ("success" == data) {
																		layer.msg("保存周报成功");
																		closeDialog();
																	}else if("TimenotEnough" == data)
																		layer.msg("工时不足" + ${workingHoursPerWeek} + "小时,请先填写完毕日报",{icon: 3});
																	else {
																		layer.msg("保存周报失败: " + data,{icon: 3});
																		//closeDialog();
																	}

																}
															});
													return false; // 阻止表单自动提交事件
												};
											});

						});

		function closeDialog() {
			var index = parent.layer.getFrameIndex("createWeeklyLog"); //先得到当前iframe层的索引
			parent.layer.close(index); //再执行关闭   
			if (parent.sendData) {
				parent.sendData();//异步
			} else {
				parent.location.reload();
			}
		}

		function cancelDialog() {
			var index = parent.layer.getFrameIndex("createWeeklyLog"); //先得到当前iframe层的索引
			parent.layer.close(index); //再执行关闭   
			if (parent.sendData) {
				parent.sendData();
			}
		}
	</script>
</body>
</html>

